package com.yanqu.road.server.cmd.orewar.cross;

import com.yanqu.road.entity.crossorewar.CrossUserOrePit;
import com.yanqu.road.pb.orewar.OreWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.orewar.OreWarMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.pb.OreWarPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = Protocol.S_CROSS_ORE_SYSTEM_RECALL_MAIL, desc = "跨服系统撤回矿坑发送奖励")
public class CrossSystemRecallPitCmd extends AbstractCommand {

	private int activityId;
	private long userId;
	private String crossPitReward;
	private long recallTime;
	private List<CrossUserOrePit> pitList;
	private int groupId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		OreWarProto.CrossSystemRecallMailMsg crossRespMsg = OreWarProto.CrossSystemRecallMailMsg.parseFrom(packet.getBytes());
		activityId = crossRespMsg.getActivityId();
		userId = crossRespMsg.getUserId();
		crossPitReward = crossRespMsg.getReward();
		recallTime = crossRespMsg.getRecallTime();
		pitList = OreWarPb.parseCrossOrePitList(crossRespMsg.getOrePitListList());
		Property allReward = PropertyHelper.parseStringToProperty(crossPitReward);
		groupId = crossRespMsg.getGroupId();

		//跨服上面已经转换成秒时间戳了，再还原回去
		Property refugeReward = OreWarMgr.crossSystemRecallRefuge(activityId,userId,recallTime * 1000,groupId);
		allReward.addProperty(refugeReward);
		OreWarMgr.crossSystemRecallRewardMail(activityId,userId,allReward,pitList,groupId);
		GamePlayer recallPlayer = GamePlayerMgr.getOnlinePlayer(userId);
		if(recallPlayer != null){
			recallPlayer.sendPacket(Protocol.U_ORE_WAR_MY_PIT_LIST, OreWarPb.parseMyOrePitListMsg(activityId, new ArrayList<>(), false));
		}
	}

	@Override
	public void sendData(GamePlayer player) {

	}
}
